

$(document).ready(function(){ 
	
    $("#basketItemsWrap li:first").hide();
    $("#slidingTopContent").hide();
	
    $("#slidingTopTrigger").live("click", function(event) {
        $("#slidingTopContent").slideToggle("slow", function(){
            if ($("#slidingTopContent").is(":visible")) {
                $("#slidingTopFooterLeft").html('<a href="no-js.htm" onclick="return false;" id="slidingTopTrigger"><img style="vertical-align: middle;" src="'+URL+'lib/images/black_basket.png" alt="Show Basket" />&nbsp;&nbsp; &#7848;n gi&#7887; h&#224;ng c&#7911;a b&#7841;n <img style="padding-left:60px;" src="'+URL+'lib/images/up_arrow.png" alt="Show Basket" /></a>');
            } else {
                $("#slidingTopFooterLeft").html('<a href="no-js.htm" onclick="return false;" id="slidingTopTrigger"><img style="vertical-align: middle;" src="'+URL+'lib/images/black_basket.png" alt="Show Basket" />&nbsp;&nbsp; Xem gi&#7887; h&#224;ng c&#7911;a b&#7841;n <img style="padding-left:60px;" src="'+URL+'lib/images/down_arrow.png" alt="Show Basket" /></a>');
            }
        });
    }); 
	
    $(".cart_button").click(function() {
        var productIDValSplitter 	= (this.id).split("_");
        var productIDVal 			= productIDValSplitter[1];

		
        if ($("#slidingTopContent").is(":visible")) {

            $("#notificationsLoader").html('<img src="'+URL+'lib/images/loading.gif">');
		
            $.ajax({  
                type: "POST",  
                url: URL+'?a=PROD&prod=BASK',  
                data: {
                    productID: productIDVal, 
                    action: "addToBasket"
                },  
                success: function(theResponse) {
				
                    if( $("#productID_" + productIDVal).length > 0){
                        $("#productID_" + productIDVal).animate({
                            opacity: 0
                        }, 500);
                        $("#productID_" + productIDVal).before(theResponse).remove();
                        $("#productID_" + productIDVal).animate({
                            opacity: 0
                        }, 500);
                        $("#productID_" + productIDVal).animate({
                            opacity: 1
                        }, 500);
                        $("#notificationsLoader").empty();
					
                    } else {
                        $("#basketItemsWrap li:first").before(theResponse);
                        $("#basketItemsWrap li:first").hide();
                        $("#basketItemsWrap li:first").show("slow");  
                        $("#notificationsLoader").empty();			
                    }
				
                }  
            }); 

        } else {
			
            $("#slidingTopContent").slideToggle("slow", function(){		
																 
                $("#slidingTopFooterLeft").html('<a href="no-js.htm" onclick="return false;" id="slidingTopTrigger"><img style="vertical-align: middle;" src="'+URL+'/lib/images/black_basket.png" alt="Show Basket" />&nbsp;&nbsp; &#7848;n gi&#7887; h&#224;ng c&#7911;a b&#7841;n <img style="padding-left:60px;" src="'+URL+'/lib/images/up_arrow.png" alt="Show Basket" /></a>');
                $("#notificationsLoader").html('<img src="'+URL+'lib/images/loading.gif">');
                $.ajax({  
                    type: "POST",  
                    url: URL+'?a=PROD&prod=BASK',  
                    data: {
                        productID: productIDVal, 
                        action: "addToBasket"
                    },  
                    success: function(theResponse) {
					
                        if( $("#productID_" + productIDVal).length > 0){
                            $("#productID_" + productIDVal).animate({
                                opacity: 0
                            }, 500);
                            $("#productID_" + productIDVal).before(theResponse).remove();
                            $("#productID_" + productIDVal).animate({
                                opacity: 0
                            }, 500);
                            $("#productID_" + productIDVal).animate({
                                opacity: 1
                            }, 500);
                            $("#notificationsLoader").empty();
						
                        } else {
                            $("#basketItemsWrap li:first").before(theResponse);
                            $("#basketItemsWrap li:first").hide();
                            $("#basketItemsWrap li:first").show("slow");  
                            $("#notificationsLoader").empty();			
                        }
					
                    }  
                }); 
				
				
                $("#slidingTopTrigger").fadeTo(4000, 1, function(){
                    $("#slidingTopContent").slideToggle("slow", function(){
                        $("#slidingTopFooterLeft").html('<a href="no-js.htm" onclick="return false;" id="slidingTopTrigger"><img style="vertical-align: middle;" src="'+URL+'lib/images/black_basket.png" alt="Show Basket" />&nbsp;&nbsp; Xem gi&#7887; h&#224;ng c&#7911;a b&#7841;n <img style="padding-left:60px;" src="'+URL+'lib/images/down_arrow.png" alt="Show Basket" /></a>');												 
                    });
					
                });

            });												 
        }
				
    });
	
	
	
    $("#basketItemsWrap li img").live("click", function(event) { 
        var productIDValSplitter 	= (this.id).split("_");
        var productIDVal 			= productIDValSplitter[1];	
	
        $("#notificationsLoader").html('<img src="'+URL+'/lib/images/loading.gif">');
	
        $.ajax({  
            type: "POST",  
            url: URL+'/?a=PROD&prod=BASK',
            data: {
                productID: productIDVal, 
                action: "deleteFromBasket"
            },  
            success: function(theResponse) {
			
                $("#productID_" + productIDVal).hide("slow",  function() {
                    $(this).remove();
                });
                $("#notificationsLoader").empty();
		
            }
					
        });  	
		
    });

});